package com.enjia.common.view;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.enjia.common.utils.ViewFinder;


/**
 * 标题头部
 * @author chenfeifei
 *
 */
public class TitleBarView {

	private ViewFinder finder;
	private View targetView;
	private Context mContext;
	
	public TitleBarView build(Context context, int layoutId){
		mContext = context;
		targetView = View.inflate(mContext, layoutId, null);
		finder = new ViewFinder(targetView);
		return this;
		
	}
	
	/**
	 * 绑定点击事件
	 * @param
	 * @return
	 */
	public TitleBarView bindOnClick(int id, View.OnClickListener onClickListener){
		View view = finder.find(id);
		if (view == null) {
			throw new IllegalArgumentException("绑定点击事件的视图不存在");
		}
		finder.onClick(id, onClickListener);
		return this;
	}

	/**
	 * 设置TextView显示内容
	 * @param id
	 * @param message
	 * @return
	 */
	public TitleBarView setTextView(int id, String message){
		TextView textView = finder.textView(id);
		if (textView == null) {
			throw new IllegalArgumentException("绑定点击视图的事件不存在");
		}
		textView.setText(message);
		return this;
	}
	
	public View create(){
		return targetView;
	}
	
}
